package com.gosun.controller;

import com.gosun.entity.User;
import com.gosun.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;


@RestController
public class UserController {

    // 依赖注入
    @Autowired
    private UserMapper userMapper;


    @RequestMapping("/getUser")
    public User user(@RequestParam String username){
        // 调用DAO层
        User user = userMapper.selectUserByName(username);
        return user;
    }

    @RequestMapping(value = "/addUser")
    public void addUser(User userReq) {
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        user.setAge(userReq.getAge());
        user.setUsername(userReq.getUsername());
        userMapper.insertUser(user);
    }


}
